///////////////////////////////////////////////////////////////////////////////
// SERVICE MAIN CALSS DEF.
//
#ifndef __SERVICEMAIN_H
#define __SERVICEMAIN_H

#include "SockDataList.h"
#include "Mbuf.h"
#include "SSocket.h"
#include "Compress.h"
#include "Iocp.h"
#include "User.h"
#include "SSocket.h"

//#ifndef _FILE_ENCODE_HAS_INCLUDED
//#include "SanleEncode.h"
//#define _FILE_ENCODE_HAS_INCLUDED
//#endif

typedef CTypedPtrArray <CPtrArray, SERVERINFO*>			ServerInfoArray;

class CServiceMain
{
public:
	DWORD	m_dwCurYear;
	DWORD	m_dwCurMonth;
	BOOL	m_bTimeOut;
	CString m_strConnect;

	DWORD m_dwLastTick;
	int m_nThreadCount;
	CIOCP<USER>m_UserBase;

public:		
	void SendAllBS(TCHAR* pBuf, int index);
	CServiceMain();
	virtual ~CServiceMain();

	void WriteLine(LPCTSTR szText);
	
	void InitParameter();
	void ServiceParameterInit();
	void ServiceParameterEnd();
	void ServiceMainLoop();

	int InitEnv();

	void InitConnect();
	BOOL GetLocalIPAddress();
	void NonePhasor( CSSocket *pSocket, CBuf& inbuf );
	BOOL AutoMataAppCmd(WAIT_RECV_DATA *wrd);
	void DisplayErrorMsg(SQLHANDLE hstmt);
	USER* GetUser(int uid);
	USER* GetUser(char *id);
	BOOL GetItemTable();
	BOOL GetServerInfoData();
	BOOL GetLoadFilterWordsList();

	void CheckFileTime();
	void TryDeleteFile(LPCTSTR szPath);
};

#endif
